package org.swinglife.log.sys.console;

import org.swinglife.log.sys.SLSystemLog;
import org.swinglife.log.sys.appender.SLConsoleAppender;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

/***
 * Created by Swinglife on 2018/5/25.
 * 系统日志控制台输出类
 */
public class SLSystemConsoleLog extends SLConsoleAppender implements SLSystemLog {



    @Override
    public void message(String message) {
        writeConsole("MESSAGE==>>"+message);
    }

    @Override
    public void debug(String debug) {

    }

    @Override
    public void error(String error) {
        writeConsole("ERROR==>>"+error);
    }

    @Override
    public void error(String error, Exception e) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        //输出的错误信息
        String exceptionMsg = printWriter.toString();
        StringBuffer sb = new StringBuffer("ERROR==>>"+error+"\n");
        sb.append("!!!!Exception:"+exceptionMsg+"\n\n");
        writeConsole(sb.toString());
    }
}
